import React from "react";
import { Descriptions } from 'antd';

import { helper } from 'vendor/utils/T';
import { mountModal, withModal, WrappedComponentProps} from "vendor/components/pro-hoc/withModal";
import type { LocalNetworkStore } from "../../model";

export const getMockAttackResult = (localNetworkStore: LocalNetworkStore) => {
    const LocalNetworkInfoModal = withModal(MockAttackResult);

    mountModal(<LocalNetworkInfoModal
        modalProps={{
            title: "模拟攻击结果",
            footer: null,
        }}
        localNetworkStore={localNetworkStore}
    />)
}

interface LocalNetworkInfoProps extends WrappedComponentProps{
    localNetworkStore: LocalNetworkStore
}

const MockAttackResult: React.FC<LocalNetworkInfoProps> = ({localNetworkStore}) => {
    const { getInitData,  localNetworkData } = localNetworkStore;
    const { localNetworkDeviceList } = getInitData();
    const deviceTypeToInfo = helper.convertArrayToObj(localNetworkDeviceList);
    const deviceTypeList = helper.uniq(localNetworkData.deviceList.map(device =>{
        return device.id.split("_").pop()
    }));

    return <Descriptions column={1} bordered>
        {deviceTypeList.map((deviceType) => {
            const { label, value } = deviceTypeToInfo[deviceType];
            return <Descriptions.Item key={value} label={`${label}受干扰程度`}>{(Math.random() * 100).toFixed(2)+"%"}</Descriptions.Item>
        })}
    </Descriptions>
}
